<template>
	<!-- 商品收藏页面 -->
	<view>
		<!-- <view class="header" :class="bjcolorclass">
			<text :style="'color:'+bjcolor+';'">商品收藏</text>
		</view> -->
		<view class="goods-section">
			<!-- 商品列表 -->
			<view class="g-item" v-for="(item,index) in list" :key='index'>
				<image :src="item.img"> </image>
				<view class="right">
					<view class="title clamp">{{item.title}}</view>
					<image src="../../static/soushang/shangcu.png" style="width: 40rpx; height: 40rpx;" class="iconfont icon-shanchu" @click="del(item)"></image>
					<view class="spec on">{{item.description}}</view>
					<view class="spec">累计销售{{item.sales}}件</view>
					<view class="price-box">
						<text class="price">￥{{item.originalPrice/100}}</text>
						<text class="number">￥{{item.price/100}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bjcolorclass: '',
				bjcolor: '#000',
				list: ''
			}
		},
		onLoad() {
			this.inltr()
		},
		onShow: function(e) {
			this.name = uni.getStorageSync('nickname')
			if (uni.getStorageSync('accessToken') == '') {
				uni.showModal({
					title: '登录提示',
					content: '您尚未登录，是否立即登录',
					success: function(res) {
						if (res.confirm) {
							uni.navigateTo({
								url: '../long/long'
							})
							return
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
			}
			this.inltr()
		},
		methods: {
			onPageScroll: function(e) {
				if (e.scrollTop <= 10) {
					this.bjcolor = "#fff";
					this.bjcolorclass = ''
				} else if (e.scrollTop <= 150) {
					this.bjcolorclass = 'topSeekbjcolorA';
					this.bjcolor = "#000";
				} else {
					this.bjcolorclass = 'topSeekbjcolorB '
				}
			},
			inltr() {
				let that = this
				uni.request({
					url: 'http://192.168.1.54:8081/m.api?_gp=collect&_mt=getCollectAll&pageNo=&pageSize=',
					method: 'GET',
					header: {
						'accesstoken': uni.getStorageSync('accessToken')
					},
					success: function(res) {
						console.log(res)
						that.list = res.data.data.items
						console.log(res)
					}
				})
			},
			del(item) {
				console.log(item.spuId)
				let data = item.spuId
				let that = this
				uni.request({
					url: 'http://192.168.1.54:8081/m.api?_gp=collect&_mt=deleteCollect&spuId='+data,
					method: 'GET',
					header: {
						'accesstoken': uni.getStorageSync('accessToken')
					},
					success: function(res) {
						that.inltr()
						console.log(res)
					}
				})
			}
		}
	}
</script>

<style scoped>
	/* .header {
		width: 100%;
		height: 80rpx;
		text-align: center;
		line-height: 80rpx;
		background-color: #F5F5F5;
	} */
	.goods-section {margin-top: 16rpx;background: #fff;padding-bottom: 1px;}
	.g-header {display: flex;align-items: center;height: 84rpx;padding: 0 30rpx;position: relative;}
	.logo {display: block;width: 50rpx;height: 50rpx;border-radius: 100px;}
	.name {font-size: 30rpx; color: #606266; margin-left: 24rpx;}
	.g-item {display: flex; margin: 20rpx 30rpx; line-height: 44rpx; border-bottom: 1px solid #f1f1f1; position: relative;}
	.g-item image {flex-shrink: 0; display: block; width: 200rpx; height: 200rpx; border-radius: 4rpx;}
	.g-item .right {flex: 1; padding-left: 24upx; overflow: hidden;}
	.g-item .title {width: 90%; font-size: 30upx; color: #303133; margin-top: 10rpx; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block;}
	.g-item .spec {font-size: 26rpx; color: #909399;}
	.g-item .price-box {display: flex; align-items: center; font-size: 32rpx; color: #303133; padding-top: 10rpx;}
	.g-item .price-box .price {margin-bottom: 4rpx; font-size: 24rpx; text-decoration: line-through;}
	.g-item .price-box .number {font-size: 26rpx; color: #606266;}
	.icon-shanchu {position: absolute; top: 6rpx; right: 0;}
</style>
